<link rel="stylesheet" type="text/css" href="../style/css/style.css" media="screen" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script type="text/javascript" src="../js/jgcharts.js"></script>
<a href="#" title='Voltar' onclick="history.back();"><img style="height: 35px; float: right;"  src="../style/img/voltar.png"></a>
<a href="#" title='Imprimir Gr&aacute;fico' onclick="window.print();"><img style="float: right;" class='acao' src="../style/img/imprimir.png"></a>
<?php
include '../inc/config.php';

function grafico_barras($total_array_na_posicao_data) {
    foreach ($total_array_na_posicao_data as $i => $valor) {
        ($valor['total'] <= 0 ? $posicoes.="[0, " . substr($valor['total'], 1) . "], " : $posicoes.="[" . $valor['total'] . ", 0], ");
        $datas.="'" . $valor[data] . "', ";
    }
    $content = "<script type='text/javascript'>
	$(document).ready(function() {

		var api = new jGCharts.Api(); 
		var chart = {   
				data : [" . $posicoes . "],
				size : '1000x300',
				type : 'bvg', 
				axis_labels : [" . $datas . "], 
				legend : ['Positivo','Negativo'],  
				".($_REQUEST[tipo]=='anual'?'bar_width : 17,':'bar_width : 11,')."
                                bar_spacing : 1, 
				colors : ['4b9b41','A6000B'], 
				bg   : 'ADADAD', 
				title       : 'Barras-" . $_SESSION[xml_data] . "', 
				title_color : '232323', 
				title_size  : 10
			};
		var chart2 = {  
				data : [" . $posicoes . "],
				size : '1000x300',
				type : 'bhg', 
				axis_labels : [" . $datas . "], 
				legend : ['Positivo','Negativo'],    
				bar_width : 10, 
				bar_spacing : 1, 
				colors : ['4b9b41','A6000B'], 
				bg   : 'e0e0e0', 
				title       : 'Barras Horizontal', 
				title_color : 'a98147', 
				title_size  : 15
			};
		jQuery('<img>').attr('src',api.make(chart)).appendTo('#grafico');
		jQuery('<img>').attr('src',api.make(chart2)).appendTo('#grafico2');
	});
</script><div id='grafico'></div>";
    return $content;
}

$i = 1;
foreach ($_SESSION[xml] as $value) {
    $dia = substr($value[data], 0, -8);
    $mes = substr($value[data], 3, -5);
    $ano = substr($value[data], 6);
    $data = substr($value[data], 3);
    if ($_REQUEST[tipo] == "anual") {
        if ($data == $data_antes) {
            $i--;
            $xy[$i][total] = $value[total];
            $xy[$i][data] = $data;
        } else {
            $xy[$i][total] = $value[total];
            $xy[$i][data] = $data;
        }
        $data_antes = substr($value[data], 3);
    } else {
        if ($value[data] == $data_antes) {
            $i--;
            $xy[$i][total] = $value[total];
            $xy[$i][data] = substr($value[data], 0, -5);
        } else {
            $xy[$i][total] = $value[total];
            $xy[$i][data] = substr($value[data], 0, -5);
        }
        $data_antes = $value[data];
    }
    $i++;
}
echo grafico_barras($xy);
//$_SESSION[xml] = "";
//$_SESSION[xml_data] = "";
?>
